#include <sys/types.h>
#include <sys/stat.h>
#include<iostream>
#include <fcntl.h>
#include<unistd.h>
#include "comm.hpp"
using namespace std;
class Pipe
{
public:
    Pipe()
    {
        int n=mkfifo(gpipepath.c_str(),0600);
        if(n<0)
        {
            cout<<"mkfifo fail"<<endl; 
        }
    }
    ~Pipe()
    {
        ::unlink(gpipepath.c_str());//
    }
};

Pipe pp;

class Server
{
public:
    Server()
    {
        _fd=::open(gpipepath.c_str(),O_RDONLY);//成功返回描述符，失败返回-1    
       
    }

    bool readpipe(int& t)
    {
        int tmp;
        int n=::read(_fd,&tmp,sizeof tmp);//成功返回读到字符个数，失败-1
        if(n<=0)
        {
            cout<<"read error"<<endl;
            return false;
        }
        t=tmp;
        return true;
    }

private:
    int _fd; 

};
